package gob.pe.mtpe.ibatis.implementacion;
import gob.pe.mtpe.bean.ListaBean;
import gob.pe.mtpe.ibatis.comun.BaseSqlMapDao;
import gob.pe.mtpe.ibatis.interfase.INTReportePoliza;
import gob.pe.mtpe.util.funciones.Funciones;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.ibatis.dao.client.DaoException;
import com.ibatis.dao.client.DaoManager;
import com.ibatis.sqlmap.client.SqlMapExecutor;

public class IMPReportePoliza extends BaseSqlMapDao implements INTReportePoliza{
    private SqlMapExecutor sqlMapExecutor;
    private static Logger depurador = Logger.getLogger(IMPReportePoliza.class.getName());
    private Funciones funciones;
    
	public IMPReportePoliza(DaoManager arg0){ super(arg0); }
	

	public List comprobante(ListaBean listaBean) throws DaoException {
		try {
			
        	System.out.println("PV_V_CODEMP==>"+listaBean.getV_codemp());
            System.out.println("PV_N_CODSUC ====>"+listaBean.getN_codsuc());
            System.out.println("PV_N_CORRPOL ====>"+listaBean.getN_corrpol());
            
        	SqlMapExecutor sqlMap = getSqlMapExecutor();
        	Map parametros = new HashMap();
            parametros.put("PV_V_CODEMP", listaBean.getV_codemp());	
            parametros.put("PV_N_CODSUC", listaBean.getN_codsuc());	
            parametros.put("PV_N_CORRPOL", listaBean.getN_corrpol());
            
            List lista= sqlMap.queryForList("comprobante",parametros);
            
            System.out.println("LISTA NUEVA====>"+lista.size());
            Map m =null;
            List tenplist= new ArrayList();
            Iterator iterator = lista.iterator();
            while (iterator.hasNext()) {
              		m = new HashMap();
                    listaBean=(ListaBean)iterator.next();
                    m.put("V_CODEMP" ,listaBean.getV_codemp());
		            m.put("N_CODSUC" ,listaBean.getN_codsuc());
		            m.put("V_RAZSOC" ,listaBean.getV_razsoc());
		            m.put("V_NUMPOL" ,listaBean.getV_numpol());
		            m.put("D_FECINIPOL" ,listaBean.getD_fecinipol());
		            m.put("D_FECFINPOL" ,listaBean.getD_fecfinpol());
		            m.put("V_CODEMPASE" ,listaBean.getV_codempase());
		            m.put("V_RAZSOCASE" ,listaBean.getV_razsocase());
		            m.put("N_NROASE" ,listaBean.getN_nroase());
		            m.put("N_NUMENV" ,listaBean.getN_numenv());
		            m.put("V_ANOENV" ,listaBean.getV_anoenv());
		            m.put("D_FECENV" ,listaBean.getD_fecenv());
                    //System.out.println(m.values());
                    tenplist.add(m);
                }
           return tenplist;
         } catch (SQLException e) {
            funciones=new Funciones();
            depurador.log(Level.ERROR,funciones.readStackTrace(e));
            throw new DaoException("");
        }
	}
    

	public List reimprimir(ListaBean listaBean) throws DaoException {
		try {
			
        	System.out.println("PV_V_CODEMP==>"+listaBean.getV_codemp());
            System.out.println("PV_N_CODSUC ====>"+listaBean.getN_codsuc());
            System.out.println("PV_N_NUMENV ====>"+listaBean.getN_numenv());
            System.out.println("PV_V_ANOENV ====>"+listaBean.getV_anoenv());
            
        	SqlMapExecutor sqlMap = getSqlMapExecutor();
        	Map parametros = new HashMap();
            parametros.put("PV_V_CODEMP", listaBean.getV_codemp());	
            parametros.put("PV_N_CODSUC", listaBean.getN_codsuc());	
            parametros.put("PV_N_NUMENV", listaBean.getN_numenv());
            parametros.put("PV_V_ANOENV", listaBean.getV_anoenv());
            
            List lista= sqlMap.queryForList("reimprimir",parametros);
            
            System.out.println("LISTA NUEVA====>"+lista.size());
            Map m =null;
            List tenplist= new ArrayList();
            Iterator iterator = lista.iterator();
            while (iterator.hasNext()) {
              		m = new HashMap();
                    listaBean=(ListaBean)iterator.next();
                    m.put("V_CODEMP" ,listaBean.getV_codemp());
		            m.put("N_CODSUC" ,listaBean.getN_codsuc());
		            m.put("V_RAZSOC" ,listaBean.getV_razsoc());
		            m.put("V_NUMPOL" ,listaBean.getV_numpol());
		            m.put("D_FECINIPOL" ,listaBean.getD_fecinipol());
		            m.put("D_FECFINPOL" ,listaBean.getD_fecfinpol());
		            m.put("V_CODEMPASE" ,listaBean.getV_codempase());
		            m.put("V_RAZSOCASE" ,listaBean.getV_razsocase());
		            m.put("N_NROASE" ,listaBean.getN_nroase());
		            m.put("N_NUMENV" ,listaBean.getN_numenv());
		            m.put("V_ANOENV" ,listaBean.getV_anoenv());
		            m.put("D_FECENV" ,listaBean.getD_fecenv());
                    //System.out.println(m.values());
                    tenplist.add(m);
                }
           return tenplist;
         } catch (SQLException e) {
            funciones=new Funciones();
            depurador.log(Level.ERROR,funciones.readStackTrace(e));
            throw new DaoException("");
        }
	}

	
	public List detalle(ListaBean listaBean) throws DaoException {
		try {
			
        	System.out.println("PV_V_CODEMP==>"+listaBean.getV_codemp());
            System.out.println("PV_N_CODSUC ====>"+listaBean.getN_codsuc());
            System.out.println("PV_V_CODEMPASE ====>"+listaBean.getV_codempase());
            System.out.println("PV_N_NUMENV ====>"+listaBean.getN_numenv());
            System.out.println("PV_V_ANOENV ====>"+listaBean.getV_anoenv());
            
        	SqlMapExecutor sqlMap = getSqlMapExecutor();
        	Map parametros = new HashMap();
            parametros.put("PV_V_CODEMP", listaBean.getV_codemp());	
            parametros.put("PV_N_CODSUC", listaBean.getN_codsuc());
            parametros.put("PV_V_CODEMPASE", listaBean.getV_codempase());
            parametros.put("PV_N_NUMENV", listaBean.getN_numenv());
            parametros.put("PV_V_ANOENV", listaBean.getV_anoenv());
            
            List lista= sqlMap.queryForList("detalle",parametros);
            
            System.out.println("LISTA DETALLE====>"+lista.size());
            Map m =null;
            List tenplist= new ArrayList();
            Iterator iterator = lista.iterator();
            while (iterator.hasNext()) {
              		m = new HashMap();
                    listaBean=(ListaBean)iterator.next();
                    m.put("V_CODEMP" ,listaBean.getV_codemp());
		            m.put("V_RAZSOC" ,listaBean.getV_razsoc());
		            m.put("V_NUMPOL" ,listaBean.getV_numpol());
		            m.put("D_FECINIPOL" ,listaBean.getD_fecinipol());
		            m.put("D_FECFINPOL" ,listaBean.getD_fecfinpol());
		            m.put("V_CODEMPASE" ,listaBean.getV_codempase());
		            m.put("V_RAZSOCASE" ,listaBean.getV_razsocase());		            
		            m.put("V_CODTRA" ,listaBean.getV_codtra());
		            m.put("V_TRABAJADOR" ,listaBean.getV_trabajador());
		            m.put("D_FECNACTRA" ,listaBean.getD_fecnactra());
		            m.put("V_GENERO" ,listaBean.getV_genero());
		            m.put("D_FECING" ,listaBean.getD_fecing());
		            m.put("V_DESTMON" ,listaBean.getV_destmon());
		            m.put("N_MONREM" ,listaBean.getN_monrem());
		            m.put("D_FECASETRA" ,listaBean.getD_fecasetra());
		            m.put("D_FECREG" ,listaBean.getD_fecreg());
		            m.put("D_FECMOD" ,listaBean.getD_fecmod());
		            m.put("V_CODBEN" ,listaBean.getV_codben());
		            m.put("V_BENEFICIARIO" ,listaBean.getV_beneficiario());		            
		            m.put("D_FECNACBEN" ,listaBean.getD_fecnacben());
		            m.put("V_DESVINFAM" ,listaBean.getV_desvinfam());
                    //System.out.println(m.values());
                    tenplist.add(m);
                }
           return tenplist;
         } catch (SQLException e) {
            funciones=new Funciones();
            depurador.log(Level.ERROR,funciones.readStackTrace(e));
            throw new DaoException("");
        }
	}


	public List trabajador(ListaBean listaBean) throws DaoException {
		try {
			
        	System.out.println("PV_V_CODEMP==>"+listaBean.getV_codemp());
            System.out.println("PV_N_CODSUC ====>"+listaBean.getN_codsuc());
            System.out.println("PV_N_CORPOL ====>"+listaBean.getN_corrpol());
            
            
        	SqlMapExecutor sqlMap = getSqlMapExecutor();
        	Map parametros = new HashMap();
            parametros.put("PV_V_CODEMP", listaBean.getV_codemp());	
            parametros.put("PV_N_CODSUC", listaBean.getN_codsuc());
            parametros.put("PV_N_CORPOL", listaBean.getN_corrpol());
            
            List lista= sqlMap.queryForList("trabajador",parametros);
            
            System.out.println("LISTA TRABAJADOR====>"+lista.size());
            Map m =null;
            List tenplist= new ArrayList();
            Iterator iterator = lista.iterator();
            while (iterator.hasNext()) {
              		m = new HashMap();
                    listaBean=(ListaBean)iterator.next();
                    m.put("V_CODEMP" ,listaBean.getV_codemp());
		            m.put("V_RAZSOC" ,listaBean.getV_razsoc());
		            m.put("V_NUMPOL" ,listaBean.getV_numpol());
		            m.put("D_FECINIPOL" ,listaBean.getD_fecinipol());
		            m.put("D_FECFINPOL" ,listaBean.getD_fecfinpol());
		            m.put("V_CODEMPASE" ,listaBean.getV_codempase());
		            m.put("V_RAZSOCASE" ,listaBean.getV_razsocase());		            
		            m.put("V_CODTRA" ,listaBean.getV_codtra());
		            m.put("V_TRABAJADOR" ,listaBean.getV_trabajador());
		            m.put("D_FECNACTRA" ,listaBean.getD_fecnactra());
		            m.put("V_GENERO" ,listaBean.getV_genero());
		            m.put("D_FECING" ,listaBean.getD_fecing());
		            m.put("V_DESTMON" ,listaBean.getV_destmon());
		            m.put("N_MONREM" ,listaBean.getN_monrem());
		            m.put("D_FECASETRA" ,listaBean.getD_fecasetra());
		            m.put("D_FECREG" ,listaBean.getD_fecreg());
		            m.put("D_FECMOD" ,listaBean.getD_fecmod());
		            m.put("V_ESTADOTRA" ,listaBean.getV_estadotra());
		            m.put("V_ESTADOPOL" ,listaBean.getV_estadopol());
                    //System.out.println(m.values());
                    tenplist.add(m);
                }
           return tenplist;
         } catch (SQLException e) {
            funciones=new Funciones();
            depurador.log(Level.ERROR,funciones.readStackTrace(e));
            throw new DaoException("");
        }
	}

}
